package managesystem;

import java.util.List;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

import IO.Hash;

public final class StudentManager {
	
	private  Student currStud;
	private  List<Student> students;
	
	public StudentManager(){
		
	}

	/**
	 * @return the currStud
	 */
	public Student getCurrStud() {
		return currStud;
	}

	/**
	 * @param currStud the currStud to set
	 */
	public void setCurrStud(Student currStud) {
		this.currStud = currStud;
	}
	
	
	public boolean verifyLogin(String un, String pw){
		boolean login = false;
		getListStudents();
		for(int i = 0; i < students.size();i++){
			Student tempstud = null;
			if(students.get(i).getUsername().equals(un)){
				tempstud = students.get(i);
				if(tempstud.getPassword().equals(Hash.getHash(pw))){
					currStud = tempstud;
					login = true;
				}
				else{
					
					login = false;
				}
			}
			else{
				login= false;
			}
		}
		
		return login;
		
	}
	
	
	public void save(Student s){
		Objectify ofy = ObjectifyService.begin();
		ofy.put(s);
	}

	public List<Student> getListStudents(){
		
		Objectify ofy = ObjectifyService.begin();
		students = ofy.query(Student.class).list();
		
		return students;
		
	}
	
	public void update(){
		Objectify ofy = ObjectifyService.begin();
		ofy.put(currStud);
	}

 
}
